#ifndef DBUSOBJMODEL_HPP
#define DBUSOBJMODEL_HPP

#include "qdbusmodel.h"
#include <QAbstractItemModel>
#include <qdom.h>

class DbusObjModel : public QAbstractItemModel
{
    Q_OBJECT
public:
    explicit DbusObjModel(QObject *parent = nullptr);
    void append(const QString &bus,const QString &service,const QString &path,const QString &interface);
    void append(QList<QStringList> data);
Q_SIGNALS:
    void busError(const QString &text);
signals:

public slots:

    // QAbstractItemModel interface
public:
    QModelIndex index(int row, int column, const QModelIndex &parent) const override;
    QModelIndex parent(const QModelIndex &child) const override;
    int rowCount(const QModelIndex &parent) const override;
    int columnCount(const QModelIndex &parent) const override;
    QVariant data(const QModelIndex &index, int role) const override;
    QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
    Qt::ItemFlags flags(const QModelIndex &index) const override;
    QDBusModel::Type itemType(const QModelIndex &index) const;
private:
    QDBusItem *root;
    QList<QStringList> m_data;
    QDBusConnection getBus(QString name)
    {
        if(name == "Session")
        {
            return QDBusConnection::connectToBus (QDBusConnection::SessionBus,"Session");
        }else if(name == "System")
        {
            return QDBusConnection::connectToBus (QDBusConnection::SessionBus,"System");
        }else
        {
            return QDBusConnection::connectToBus (name,name);
        }
    }

    QDomDocument introspect(const QString &service,const QString &path,QDBusConnection bus);
    void addMethods(QDBusItem *parent, const QDomElement &iface);
    void addPath(QDBusItem *parent,const QString &bus,const QString &service,const QString &path,const QString &interface);
};















#endif // DBUSOBJMODEL_HPP
